package com.jvup.gameshow.controller;

import android.view.View;

import com.jvup.common.support.base.EventController;
import com.jvup.common.constant.Navigation;
import com.jvup.common.utils.ToastHelper;
import com.jvup.gameshow.activity.ShareIdeaActivity;
import com.jvup.gameshow.activity.ImagePickerActivity.PickerImageListener;
import com.jvup.gameshow.databinding.LayoutShareIdeaPictureBinding;
import com.jvup.gameshow.model.viewModel.impl.ShareIdeaViewModel;
import com.jvup.gameshow.model.viewModel.impl.ShareIdeaViewModel.ShareIdeaPictureItemViewModel;
import com.jvup.common.widget.adapter.auto.AutoVariable;
import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;

public class ShareIdeaController extends EventController<ShareIdeaActivity> implements AutoVariable<LayoutShareIdeaPictureBinding> {

    ShareIdeaViewModel viewModel;

    public ShareIdeaController(ShareIdeaActivity activity) {
        super(activity);
    }

    @Override
    protected void bindView() {
//        owner.viewDataBinder().setVariable(BR.shareIdeaController, this);
        owner.viewDataBinder().setShareIdeaController(this);
    }

    @Override
    public void bindVariable(LayoutShareIdeaPictureBinding viewBind) {
        viewBind.setShareIdeaController(this);
    }

    public void bindViewModel(ShareIdeaViewModel viewModel) {
        this.viewModel = viewModel;
        viewModel.bindEventProcess(this);
    }


    /**
     * 返回按钮事件
     * @param view
     */
    public void goBackBtnOnClick(View view){
        owner.finish();
    }

    /**
     * 提交按钮事件
     */
    public void submitBtnOnClick(View view) {
        String ideaContent = viewModel.getIdeaContentValue();
        ToastHelper.showToast(ideaContent);

    }

    /**
     * 添加图片
     */
    public void addPictureBtnOnClick(View view) {
        ShareIdeaPictureItemViewModel itemViewModel = (ShareIdeaPictureItemViewModel) view.getTag();
        if(itemViewModel.isBtn) {
            if(viewModel.remainingCount() <= 0) {
                return;
            }
            AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ImagePickerPage)
                    .withData("maxCount",viewModel.remainingCount())
                    .withData("pickerImageListener",(PickerImageListener)viewModel::onPickerImage)
                    .navigation();
        } else {

        }
    }

    /**
     * 删除图片
     */
    public void delPictureBtnOnClick(View view){
        viewModel.deletePictureItem((ShareIdeaPictureItemViewModel) view.getTag());
    }
}
